<template>
    <div>
        
    </div>
</template>

<script>
import NProgress from 'nprogress'

NProgress.configure({ showSpinner: false })
export default {
    name: 'singleSignLogin',
    data() {
        return {
            redirect: undefined,
            singleSign: {

            }
        }
    },
    watch: {
        $route: {
            handler: function (route) {
                this.redirect = route.query && route.query.redirect;
            },
            immediate: true,
        },
    },
    created() {
        this.loading = this.$loading({
            lock: true,
            text: "开始检测凭证合法性...",
            background: "rgba(0, 0, 0, 0.7)",
        });
        this.checkCodeAvaild();
    },
    methods: {
        checkCodeAvaild() {
            NProgress.start();
            //凭证code，使用一次后失效
            var code = this.$route.query.code;
            console.log(
                code
            )
            if (!code) {
                this.closeLoad();
            } else {
                this.$store.dispatch("SimgleSignLogin", {
                    ticket: code
                }).then(() => {
                    this.closeLoad();
                    localStorage.setItem("selected", 0);
                    this.$router.push({ path: this.redirect || "/" }).catch(() => { });
                }).catch(() => {
                    this.closeLoad();
                });
            }
        },
        closeLoad() {
            this.loading.close();
            NProgress.done();
        }
    }
}
</script>

<style scoped>
html,
body,
#app {
    height: 100%;
    margin: 0px;
    padding: 0px;
}
</style>